<!--编辑器基础样式-->
<link rel="stylesheet" href="__ADMIN__/css/codemirror/lib/codemirror.css">
<script src="__ADMIN__/css/codemirror/lib/codemirror.js"></script>

<!--引入css文件，用以支持主题-->
<link rel="stylesheet" href="__ADMIN__/css/codemirror/theme/seti.css">
<!--支持代码折叠-->
<link rel="stylesheet" href="__ADMIN__/css/codemirror/addon/fold/foldgutter.css"/>
<script src="__ADMIN__/css/codemirror/addon/fold/foldcode.js"></script>
<script src="__ADMIN__/css/codemirror/addon/fold/foldgutter.js"></script>
<script src="__ADMIN__/css/codemirror/addon/fold/brace-fold.js"></script>
<script src="__ADMIN__/css/codemirror/addon/fold/comment-fold.js"></script>

<!--全屏模式-->
<link rel="stylesheet" href="__ADMIN__/css/codemirror/addon/display/fullscreen.css">
<script src="__ADMIN__/css/codemirror/addon/display/fullscreen.js"></script>

<!--括号匹配-->
<script src="__ADMIN__/css/codemirror/addon/edit/matchbrackets.js"></script>

<!--高亮库-->
<script src="__ADMIN__/css/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="__ADMIN__/css/codemirror/mode/clike/clike.js"></script>

<script src="__ADMIN__/css/codemirror/mode/javascript/javascript.js"></script>

<script src="__ADMIN__/css/codemirror/mode/css/css.js"></script>
<script src="__ADMIN__/css/codemirror/mode/php/php.js"></script>
<script src="__ADMIN__/css/codemirror/mode/xml/xml.js"></script>
<script src="__ADMIN__/css/codemirror/mode/sql/sql.js"></script>
<script src="__ADMIN__/css/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<!--自动补全库-->
<link rel="stylesheet" href="__ADMIN__/css/codemirror/addon/hint/show-hint.css">

<script src="__ADMIN__/css/codemirror/addon/hint/show-hint.js"></script>
<script src="__ADMIN__/css/codemirror/addon/hint/javascript-hint.js"></script>
<script src="__ADMIN__/css/codemirror/addon/hint/html-hint.js"></script>
<script src="__ADMIN__/css/codemirror/addon/hint/xml-hint.js"></script>
<script src="__ADMIN__/css/codemirror/addon/hint/css-hint.js"></script>
<script src="__ADMIN__/css/codemirror/addon/hint/sql-hint.js"></script>
<style>
#asd1{position: absolute;z-index: 999998;top: 0px;right: 0;width:50%;background: #fff;font-size: 15px;padding:20px; display: none}
#asd1 li{margin-bottom:10px }
</style>
<div id="main" role="main">
		<div class="tab-content tab-addtabs">
			<div id="content">
				<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
						 <div class="content">
							<form class="layui-form" >
									<div class="layui-form-item">
										<label class="layui-form-label">
											代码内容
										</label>
										<div class="layui-input-block">
											<textarea id="code">{:file_get_contents($url)}</textarea>
										</div>
									</div>

									<div class="layui-form-item" style="position: absolute;z-index: 99999999999999999999999999999;bottom: 10px;left:10px">
										<label class="layui-form-label">
											创建备份
										</label>
										<div class="layui-input-block">
											<input type="checkbox" name="type" lay-skin="switch" checked>
										</div>
									</div>
									<div class="layui-form-item" style="position: absolute;z-index: 99999999999999999999999999999;bottom: 10px;left:180px">
										<label class="layui-form-label">
											备份列表
										</label>
										<div class="layui-input-block">
											<input type="checkbox" name="status" lay-skin="switch" lay-filter="filter">
										</div>
									</div>
									
									<div id="asd1" style="">
										<table  class="table table-striped table-bordered table-hover" width="100%">
											<thead>
												<tr>
													<th><div class="th-inner">文件名</div></th>
													<th><div class="th-inner">备份时间</div></th>
													<th><div class="th-inner">操作</div></th>
												</tr>
											</thead>
											
											<tbody >
												{foreach name="list" item="v"}
												<tr id="d_{$key}">
													<td align="center">{$v.name}</td>
													<td align="center">{$v.time|date='Y-m-d H:i:s', ###}</td>
													<td style="text-align: center; vertical-align: middle; ">
														{if condition="$adminController->vif('codefile','restore')"}
														<a href="javascript:restore('{:url('restore', ['name'=>url_tran($v['url']), 'url'=>url_tran($url)])}');" class="btn btn-xs btn-success btn-editone" title="还原">
															<i class="fa fa-hand-scissors-o"></i>
														</a>
														{/if}
														{if condition="$adminController->vif('codefile','delete')"}
															<a href="javascript:del('{:url('delete', ['name'=>url_tran($v['url'])])}', 'd_{$key}');" class="btn btn-xs btn-danger btn-delone del_menu" title="删除">
																<i class="fa fa-trash"></i>
															</a>
														{/if}
													</td>
												</tr>
												{/foreach}
											</tbody>
										</table>
									</div>

							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
												
<script>
// 删除
function del(href, id) {
	$.ajax({
		type: 'post',
		data: {},
		url: href,
		success: function(data) {
			var array = eval('('+data+')');
			if (array['code'] == '01') {
				$.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:200000000});
			} else {
				$.thinkmimi({Content : array['msg'], Type:1, Align:'right', OutTime:2000});
				$('#'+id).remove();
			}
		}
	});
}
// 恢复
function restore(href, id) {
	$.ajax({
		type: 'post',
		data: {},
		url: href,
		success: function(data) {
			var array = eval('('+data+')');
			if (array['code'] == '01') {
				$.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:200000000});
			} else {
				$.thinkmimi({Content : array['msg'], Type:1, Align:'right', OutTime:2000});
				window.setTimeout(function(){
					window.location.reload();
				}, 700);
			}
		}
	});
}

$('.layui-form').css('height', $(window).height()+'px');
$('#asd1').css('height', ($(window).height()-40)+'px');
var model = '{$type}';
if(model == 'php') {
	model = 'application/x-httpd-php';
}else{
	model = 'text/html';
}
var type   = {
	// 高亮显示-关联着自动补齐
	/**
	 * application/x-httpd-php
	 * text/css
	 * text/javascript
	 * text/html
	 * text/x-sql
	*/
	mode:'application/x-httpd-php',

	//显示行号
	lineNumbers:true,

	//设置主题
	theme:"seti",

	//代码折叠
	lineWrapping:true,
	foldGutter: true,
	gutters:["CodeMirror-linenumbers", "CodeMirror-foldgutter"],

	//全屏模式
	fullScreen:true,

	//括号匹配
	matchBrackets:true,
	completeSingle: false,
	selectionPointer: true,
	// 按下ctrl键唤起智能提示
	extraKeys:{
		"Ctrl": "autocomplete",
	}
};
var editor = CodeMirror.fromTextArea(document.getElementById("code"), type);

layui.use(['form'], function(){
	var form = layui.form;
	form.on('switch(filter)', function(data){
		if(data.elem.checked) {
			$('#asd1').show(500);
		} else {
			$('#asd1').hide(500);
		}
	}); 
});

function doSubimt() {
	var res;
	var content = editor.getValue();
	var type    = 0;
	if ($("input[name='type']").is(':checked')) {
		type = 1;
	}

	var data = {
		'content':content,
		'type':type,
		'name':'{:url_tran($url)}'
	};

	$.ajax({
		type: 'post',
		data: data,
		async: false,
		url: "{:url('upd')}",
		success: function(data) {
			var array = eval('('+data+')');
			res = array;
			if (array['code'] == '01') {
				$.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:2000});
				res = false;
			}
		}
	});

	return res;
}
</script>